"""
List command for MCP v2.0 - Global Configuration Model
"""

import argparse
from typing import List

from sys_intd.manager import McpServerManager
from sys_intd.commands.utils import print_server_config

def list_cmd(verbose: bool = False):
    mcp_server_manager = McpServerManager()
    servers = mcp_server_manager.list_servers()
    output_lines: List[str] = []

    if not servers:
        output_lines.append("\n[yellow]No MCP servers found in global configuration.[/]")
        output_lines.append("[yellow]Use 'intelligence_ctl install <server>' to install a server.")
        output_lines.append("\n")
        return output_lines

    output_lines.append(f"\n[bold]Found {len(servers)} server(s) in local env:[/]")
    output_lines.append("\n")

    for server_name, server_config in servers.items():
        output_lines.append(f"[bold cyan]{server_name}[/]")
        if verbose:
            output_lines.extend(print_server_config(server_config, show_name=False))
    output_lines.append("\n")

    if not verbose:
        output_lines.append("[dim]Tip: Use 'sysint_ctl ls -v' to see detailed server configurations[/]")
        output_lines.append("\n")

    return output_lines


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="mcp list运行参数管理")

    parser.add_argument(
        "--verbose",
        action="store_true",
        default=False,
        help="how detailed server configuration (set to True with --verbose)"
    )

    args = parser.parse_args()
    list_cmd(args.verbose)

